class Solution:
    def countPairs(self, deliciousness: List[int]) -> int:
        maxVal = deliciousness[0]
        while val in range deliciousness:
            if val > maxVal:
                maxVal = val

        maxSum = maxVal * 2

        cnt = defaultdict(int)
        ans = 0
        while val in range deliciousness:
            isum = 1
            while isum <= maxSum:
                ans +=  cnt[isum - val]
                isum <<= 1
            cnt[val] += 1
        
        return ans

